<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<style type="text/css">
<!--
.stylethem {
	color: #000 !important;
	font-weight: bold !important;
	font-size: 24px !important;
}
.stylethem1 {font-weight: bold !important;}
-->
</style>
<script language="JavaScript" type="text/javascript" src="ckeditor/ckeditor.js"></script>
<script language="JavaScript" type="text/javascript" src="ckeditor/sample.js"></script>
<script type="text/javascript" >
	function ham_jjj_3()
	{
		document.getElementById("sss2").style.display="block";
	}
</script>
</head>
<body>
<?php
	empty_forder("../images/upload_tam/");
	$id=$_REQUEST["id"];
	$result=mysql_query("SELECT * FROM sanpham WHERE masanpham = $id");
	$row=mysql_fetch_assoc($result);
		$tensanpham = $row['tensanpham'];
		$madanhmuc = $row['madanhmuc'];
		$maloaidanhmuc = $row['maloaidanhmuc'];
		$mahangsanxuat = $row['mahangsanxuat'];
		$maxuatxu = $row['maxuatxu'];
		$giaban = $row['giaban'];
		$giathitruong = $row['giathitruong'];
		$xuatxu = $row['xuatxu'];
		$baohanh = $row['baohanh'];
		$hangsanxuat = $row['hangsanxuat'];
		$chitiet = $row['chitiet'];
		$tinhnang = $row['tinhnang'];
		$khuyenmai = $row['khuyenmai'];
		$tinhtrang = $row['tinhtrang'];
		$ha = $row["hinhanh"];
		$hinhanh=$row["hinhanh"];
		$hinhanh="../images/sanpham/".$hinhanh;
		//$nhieuhinhanh = $row['nhieu_hinh_anh'];
	function dequy_option__mnn($id,$nhandang)
		{
			$nhandang="&nbsp;&nbsp;&nbsp;".$nhandang;
			$a=mysql_query("select * from danhmucsp where parent = $id order by madanhmuc");
			while($b=mysql_fetch_array($a))
			{
				echo"<option value=\"$b[madanhmuc]\">$nhandang $b[tendanhmuc]</option>";
				dequy_option__mnn($b['madanhmuc'],$nhandang);
			}
		}
?>

    <form action="<?php echo "?thamso=suasanpham&id=$id"; ?>" method="post" enctype="multipart/form-data" name="form1">
      <table width="400" border="0" align="center" cellpadding="3" cellspacing="3">
        <tr align="center" bgcolor="#333333">
          <td colspan="2"><span class="stylethem">Thông tin sản phẩm</span></td>
        </tr>
        <tr bgcolor="#F2F2F2">
            <td width="20%">
                <strong>Tên Sản Phẩm: </strong>
            </td>
            <td width="80%">
                <input type='text' name='txttsp' size='50' value="<?php	echo $tensanpham;	?>"/>
            </td>
        </tr>
        <tr>
			<td width="20%">
            	<strong>Thuộc Thể Loại: </strong>
            </td>
            <td width="80%">
            	<?php
						$sql1="select * from loaidanhmuc where maloaidanhmuc = $maloaidanhmuc";
						$result1=mysql_query($sql1);
						$row1=mysql_fetch_array($result1);
						echo "<strong>thể loại hiện tại: </strong>";
						$tldm=$row1['tenloaidanhmuc'];
						echo "&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
						echo "<input type='text' name='showdanhmuc' size='20' value='$tldm' style='text-align:center'/>";
						echo "&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
						echo "<strong>sửa thành: </strong>";
						echo "<select name=\"thuoctheloai\" id=\"thuoctheloai\">";
						print '<option value="rong">&nbsp;</option>';
						$sql="select * from loaidanhmuc order by maloaidanhmuc";
						$result=mysql_query($sql);
						while($row=mysql_fetch_array($result))
							{
								print '<option value="'.$row['maloaidanhmuc'].'">'.$row['tenloaidanhmuc'].'</option>';
							}
						echo "</select>";
				?>
            </td>
        </tr>
        <tr>
			<td width='20%'><strong>Thuộc Danh Mục: </strong></td>
			<td width='80%'>
            	<?php
					echo "<strong>danh mục hiện tại: </strong>";
					$sql="select * from danhmucsp where madanhmuc = $madanhmuc order by madanhmuc";
					$result=mysql_query($sql);
					$row1=mysql_fetch_array($result);
					$tdm=$row1['tendanhmuc'];
					echo "&nbsp; &nbsp;&nbsp;&nbsp;";
					echo "<input type='text' name='showdanhmuc' size='20' value='$tdm' style='text-align:center'/>";
					echo "&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
					echo "<strong>sửa thành: </strong>"; 
					echo "<select name=\"thuocdanhmuc\" id=\"thuocdanhmuc\">";
						print '<option value="rong">&nbsp;</option>';
						$sql1="select * from loaidanhmuc order by maloaidanhmuc";
						$result1=mysql_query($sql1);
						while($row1=mysql_fetch_array($result1))
						{
							$tldm=$row1['tenloaidanhmuc'];
							$z= $row1['maloaidanhmuc'];
							echo "<optgroup label='$tldm'>";
							$sql="select * from danhmucsp where parent = 0 and maloaidanhmuc = $z order by madanhmuc";
							$result=mysql_query($sql);
							while($row=mysql_fetch_array($result))
								{
									print '<option value="'.$row['madanhmuc'].'">'.$row['tendanhmuc'].'</option>';
									dequy_option__mnn($row['madanhmuc'],"");
								}
							echo "</optgroup>";
						}
					echo "</select>";
				?>
            </td>
        </tr>
        <tr>
			<td width="20%">
            	<strong>Hãng sản xuất: </strong>
            </td>
            <td width="80%">
            	<?php
						$sql1="select * from hangsanxuat where mahangsanxuat = $mahangsanxuat";
						$result1=mysql_query($sql1);
						$row1=mysql_fetch_array($result1);
						echo "<strong>hãng sản xuất hiện tại: </strong>";
						$tldm=$row1['tenhangsanxuat'];
						echo "&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
						echo "<input type='text' name='showdanhmuc' size='20' value='$tldm' style='text-align:center'/>";
						echo "&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
						echo "<strong>sửa thành: </strong>";
						echo "<select name=\"hangsanxuat\" id=\"hangsanxuat\">";
						print '<option value="rong">&nbsp;</option>';
						$sql="select * from hangsanxuat order by mahangsanxuat";
						$result=mysql_query($sql);
						$dem = mysql_num_rows($result);
						while($row=mysql_fetch_array($result))
							{	
								print '<option value="'.$row['mahangsanxuat'].'">'.$row['tenhangsanxuat'].'</option>';
							}
						echo "</select>";
				?>
            </td>
        </tr>
        <tr>
			<td width="20%">
            	<strong>Xuất xứ: </strong>
            </td>
            <td width="80%">
            	<?php
						$sql1="select * from xuatxu where maxuatxu = $maxuatxu";
						$result1=mysql_query($sql1);
						$row1=mysql_fetch_array($result1);
						echo "<strong>Xuất xứ sản phẩm hiện tại: </strong>";
						$tldm=$row1['xuatxu'];
						echo "&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
						echo "<input type='text' name='showdanhmuc' size='20' value='$tldm' style='text-align:center'/>";
						echo "&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
						echo "<strong>sửa thành: </strong>";
						echo "<select name=\"xuatxu\" id=\"xuatxu\">";
						print '<option value="rong">&nbsp;</option>';
						$sql="select * from xuatxu order by maxuatxu";
						$result=mysql_query($sql);
						$dem = mysql_num_rows($result);
						while($row=mysql_fetch_array($result))
							{	
								print '<option value="'.$row['maxuatxu'].'">'.$row['tenxuatxu'].'</option>';
							}
						echo "</select>";
				?>
            </td>
        </tr>
        <tr bgcolor="#F2F2F2">
        	<td width='20%'><strong>Hình Ảnh: </strong></td>
        	<td width='80%'> 
            	<input type='file' name='hinh' style="width:100px" /><br />
                <?php  echo"<img src=$hinhanh width='100px' height='100px'  ></img>";?>
          	</td>
        </tr>        
        <tr bgcolor="#F2F2F2">
        	<td width='20%'><strong>Tình Trạng: </strong></td>
			<td width='80%'>
            	<strong>Còn Hàng </strong><input type='checkbox' name='conhang' 
            	<?php 
					if ($tinhtrang == 1)
					{
						echo "checked='checked'";
					
				 ?>/>
                 <?php 
					echo "<strong>&nbsp;&nbsp;&nbsp;&nbsp;sản phẩm còn hàng</strong>";
					}
					else echo "<strong>&nbsp;&nbsp;&nbsp;&nbsp;sản phẩm đã hết hàng</strong>";
					
				 ?>
			</td>
        </tr>       
        <tr>
			<td><strong>Bảo Hành : </strong></td>
			<td><input type='text' name='baohanh' size='50' value="<?php	echo $baohanh;	?>"/></td>
		</tr>        
        <tr>
			<td><strong>Giá Thị Trường : </strong></td>
			<td><input type='text' name='giathitruong' size='50' value="<?php	echo $giathitruong;	?>"/></td>
		</tr>
        <tr>
			<td><strong>Giá Bán : </strong></td>
			<td><input type='text' name='giaban' size='50' value="<?php	echo $giaban;	?>"/></td>
		</tr>
        <tr>
			<td width="20%" style="vertical-align: middle;">
            <strong>Khuyến Mãi:</strong> 
            </td>
			<td width="80%">
				<textarea id='khuyenmai' name='khuyenmai' rows='60' cols='200'><?php	echo $khuyenmai;	?></textarea>
                	<?php
								include_once ('ckeditor/ckeditor.php') ;
								require_once ('ckfinder/ckfinder.php') ;
								$ckeditor = new CKEditor( ) ; 
								$ckeditor->basePath = '/images/' ;
								CKFinder::SetupCKEditor( $ckeditor, 'ckfinder/' ) ;
								$ckeditor->replace("khuyenmai");
					?>
			</td>
		</tr>
        <tr>
			<td width='20%' style="vertical-align: middle;">
            	<strong>Chi Tiết: </strong>
            </td>
			<td width='80%'>
            	<textarea id="chitiet" name="chitiet" rows="60" cols="200"><?php	echo $chitiet;	?></textarea>
    				<?php
								include_once ('ckeditor/ckeditor.php') ;
								require_once ('ckfinder/ckfinder.php') ;
								$ckeditor = new CKEditor( ) ; 
								$ckeditor->basePath = '/images/' ;
								CKFinder::SetupCKEditor( $ckeditor, 'ckfinder/' ) ;
								$ckeditor->replace("chitiet");
					?>    
			</td>
        </tr>
        <tr>
			<td width='20%' style="vertical-align: middle;">
            	<strong>Tính Năng: </strong>
            </td>
			<td width='80%'>
            	<textarea id="tinhnang" name="tinhnang" rows="60" cols="200"><?php	echo $tinhnang;	?></textarea>
    				<?php
								include_once ('ckeditor/ckeditor.php') ;
								require_once ('ckfinder/ckfinder.php') ;
								$ckeditor = new CKEditor( ) ; 
								$ckeditor->basePath = '/images/' ;
								CKFinder::SetupCKEditor( $ckeditor, 'ckfinder/' ) ;
								$ckeditor->replace("tinhnang");
					?>    
			</td>
        </tr>
        <tr align="center" bgcolor="#CFCFCF">
        	<td width='20%'>&nbsp;</td>
			<td width='80%'><input type="submit" class="nut_chapnhan" value="Chấp nhận" name="them"></td>
        </tr>  
      </table>
    </form>
</body>
</html>
<?php
	function upload_anh(){
		$hinh=$_FILES["hinh"]["name"];
		$duongdan_upload_anh="../images/sanpham/$hinh";
		chong_90($hinh);
		move_uploaded_file($_FILES["hinh"]["tmp_name"],$duongdan_upload_anh);
	}
	function chuoi_nhieu_hinh_anh()
	{
		$mang=getDirectoryList("../images/upload_tam/");
		// ham getDirectoryList :lay danh sach file trong thu muc , tra ve mang
		$chuoi="";
		for($i=0;$i<count($mang);$i++)
		{
			$chuoi=$chuoi.$mang[$i]."____";
		}
		if($chuoi=="____")
		{
			$chuoi="";
		}
		return $chuoi;
	}
	function ktfile($tenfile)
	{
		$pattern='#.+\.(gif|jpg|png)$#i';
		if(preg_match($pattern,$tenfile)==1)
		{
    		return 1;
		}
		else
		{
    		return 0;
		}
	}
	if(isset($_POST["them"]))
	{
		/*if($_FILES["hinh"]["size"]>2000000)
		{
			echo"<script>alert('File Vượt quá dung lượng cho phép');</script>";
			return;
		}
		else
		{*/
			/*if($_FILES["hinh"]["error"]>0)
			{	
				echo"<script>alert('Lỗi Upload File')</script>";
				return;
			}
			else
			{*/
				if(ktfile($_FILES["hinh"]["name"])==1)
				{	
					//move_uploaded_file($_FILES["hinh"]["tmp_name"],"../images/".$_FILES["hinh"]["name"]);
					$hinh=$_FILES["hinh"]["name"];
				}
				/*else
				{
					echo"<script>alert('Đuôi file không đúng')</script>";
				}*/
			//}
		//}		
		$tensanpham = $_POST['txttsp'];
		$madanhmuc1 = $_POST['thuocdanhmuc'];
		if ($madanhmuc1=="rong")
		$madanhmuc1 = $madanhmuc;
		$maloaidanhmuc1 = $_POST['thuoctheloai'];
		if ($maloaidanhmuc1=="rong")
		$maloaidanhmuc1 = $maloaidanhmuc;
		$mahangsanxuat1 = $_POST['hangsanxuat'];
		if ($mahangsanxuat1=="rong")
		$mahangsanxuat1 = $mahangsanxuat;
		$maxuatxu1 = $_POST['xuatxu'];
		if ($maxuatxu1=="rong")
		$maxuatxu1 = $maxuatxu;
		$giaban = $_POST['giaban'];
		$giathitruong = $_POST['giathitruong'];
		$xuatxu = $_POST['xuatxu'];
		$baohanh = $_POST['baohanh'];
		$hangsanxuat = $_POST['hangsanxuat'];
		$chitiet = $_POST['chitiet'];
		$tinhnang = $_POST['tinhnang'];
		$khuyenmai = $_POST['khuyenmai'];
		if ($_POST['conhang'] == 'on')
			{
				$tinhtrang = 1;
			}
		else	$tinhtrang = 0;
		if ($hinh == "")
		$hinh = $ha;
		else chong_90($hinh);
		$sql = "UPDATE `sanpham` SET `tensanpham` = '$tensanpham', `hinhanh` = '$hinh', `tinhtrang` = '$tinhtrang', 
		`giaban` = '$giaban', `chitiet` = '$chitiet', `tinhnang` = '$tinhnang', 
		`khuyenmai` = '$khuyenmai', `madanhmuc` = '$madanhmuc1', `maloaidanhmuc` = '$maloaidanhmuc1', `giathitruong`='$giathitruong', 
		`maxuatxu` = '$maxuatxu1', `baohanh` = '$baohanh', `mahangsanxuat`='$mahangsanxuat1'
		WHERE `masanpham` = $id";
		$result = mysql_query($sql);		
		if($result)
		{
			echo "<script>alert('Sửa thành công');</script>";
			echo "<script>window.location=('?thamso=dssanpham');</script>";
		}
		upload_anh();
	}		
?>